package com.booking.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.booking.common.dto.PageReq;
import com.booking.common.dto.PageResp;
import com.booking.common.utils.ConvertUtils;
import com.booking.controller.model.req.grouping.GroupingQueryReq;
import com.booking.dao.entity.GroupingInfo;
import com.booking.dao.mapper.GroupingInfoMapper;
import com.booking.dao.service.GroupingInfoService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

/**
 * @author Qikai.Lin
 * @date 2023/4/23
 */
@Service
public class GroupingInfoServiceImpl extends ServiceImpl<GroupingInfoMapper, GroupingInfo>
        implements GroupingInfoService {
    @Override
    public PageResp<GroupingInfo> getPage(PageReq<GroupingQueryReq> request) {
        GroupingQueryReq condition = request.getCondition();
        QueryWrapper<GroupingInfo> pageQueryWrapper = new QueryWrapper<>();
        pageQueryWrapper.like(Strings.isNotEmpty(condition.getName()), "name", condition.getName());
        Page<GroupingInfo> groupingInfoPage = new Page<>(request.getCurrent(), request.getSize());
        Page<GroupingInfo> page = this.page(groupingInfoPage, pageQueryWrapper);
        return ConvertUtils.convert(PageResp.class, page);
    }
}
